﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Share.Models;

namespace Share.Utils
{
    public class CategoryUtil
    {
        public static IEnumerable<Category> CategoryTreeList(IEnumerable<Category> cats)
        {
            List<Category> tl = new List<Category>();

            foreach (Category cat in cats)
            {
                tl.Add(new Category { ID = cat.ID, Name = cat.Name });
                if (cat.SubCategories != null)
                    tl = tl.Concat(CategoryTreeList(cat.SubCategories).Select(c => new Category { ID = c.ID, Name = "--" + c.Name })).ToList();
            }

            return tl;
        }
    }
}
